<?php
header("Content-Type: text/html; charset=iso-8859-1");
require 'include.php';
$search = (!empty($_REQUEST['search'])) ? $_REQUEST['search'] : "";
if(strlen($search) > 2){
	$found = 0;
	echo "<h1>Recherche</h1>\n";
	$q = "select id from membres where (nom like '$search%' or prenom like '$search%') and valide = 1 and fictif = 0";
	$r = ExecRequete($q);
	$i = 0;
	while($s = LigneSuivante($r)){
		$found = 1;
		if(++$i == 1){
			echo "<h2>Les membres</h2>\n";	
			echo "<table><tr><th>Pr&eacute;nom</th><th>Nom</th><th>Equipes</th><th></th></tr>\n";
		}
		$membre = new membre($s->id);
		echo "<tr><td>$membre->prenom</td><td>$membre->nom</td><td>".(implode(", ",$membre->equipes))."</td><td class = 'center'><img src = 'images/icon_search.png' alt = '?' height = '14' width = '14' style = 'cursor: pointer' onclick = 'show_membre($s->id)' /></td></tr>\n";
	}
	if($i) echo "</table>\n";
	$q = "select id,no from salles where (nom like '%$search%' or localite like '%$search%' or no = '$search') and no != 0";
	$r = ExecRequete($q);
	$i = 0;
	while($s = LigneSuivante($r)){
		$found = 1;
		if(++$i == 1){
			echo "<h2>Les salles</h2>\n";	
			echo "<table><tr><th>No</th><th>Nom</th><th>Localite</th><th>Adresse</th><th>Carte</th></tr>\n";
		}
		$salle = new salle($s->no);
		echo "<tr><td>$salle->no</td><td>$salle->nom</td><td>$salle->localite</td><td>$salle->adresse</td><td class = 'center'><img src = 'images/icon_map.png' alt = '?' height = '14' width = '14' style = 'cursor: pointer' onclick = 'show_salle($salle->no)' /></td></tr>\n";
	}
	if($i) echo "</table>\n";
	$q = "select infos.id as id from infos left join membres on membre_id = membres.id where (infos.titre like '%$search%'  or nom like '$search%' or prenom like '$search%') and infos.valide = 1 order by datetime desc";
	$r = ExecRequete($q);
	$i = 0;
	while($s = LigneSuivante($r)){
		$found = 1;
		if(++$i == 1){
			echo "<h2>Les infos</h2>\n";	
			echo "<table><tr><th>Date</th><th>Titre</th><th>Auteur</th><th></th></tr>\n";
		}
		$info = new info($s->id);
		$auteur = new membre($info->membre_id);
		echo "<tr><td>".(format_date($info->datetime))."</td><td>$info->titre</td><td>$auteur->prenom $auteur->nom</td><td class = 'center'><img src = 'images/icon_search.png' alt = '?' height = '14' width = '14' style = 'cursor: pointer' onclick = 'self.location.href=\"infos.php?id=$s->id\"' /></td></tr>\n";
	}
	if($i) echo "</table>\n";
	$q = "select historique.id as id from historique  where (titre like '%$search%' or corps like '%$search%') and valide = 1 order by date desc";
	$r = ExecRequete($q);
	$i = 0;
	while($s = LigneSuivante($r)){
		$found = 1;
		if(++$i == 1){
			echo "<h2>L'historique</h2>\n";	
			echo "<table><tr><th>Date</th><th>Titre</th><th>P&eacute;riode</th><th></th></tr>\n";
		}
		$info = new historique($s->id);
		echo "<tr><td class = 'center'>".(format_date($info->date))."</td><td>$info->titre</td><td class = 'center'>$info->periode</td><td class = 'center'><img src = 'images/icon_search.png' alt = '?' height = '14' width = '14' style = 'cursor: pointer' onclick = 'self.location.href=\"historique.php?article=$s->id&search=1\"' /></td></tr>\n";
	}
	if($i) echo "</table>\n";

	if(!$found) echo "<p class = 'center fade'>Le r&eacute;sultat de la recherche est vide</p>\n";

}
?>
